//	ID: 066498650
//	Exercise #: 2
//	By:	Roy Moore
//
//	Written:	19/12/2011
//	Environment : VS2010
//
//-main.cpp-

#include "UDPTimeServer.h"
#include "UDPTimeClient.h"

void main(){
	enum ROLE app_role;
	int selection;

	cout << "Please select Application role" << endl << "1. Client" << endl << "2. Server" << endl;
	cin >> selection;

	system("cls");

	if (selection == 1){
		app_role = Client;
		cout << "----------Client----------" << endl;
	}
	else if (selection == 2){
		app_role = Server;
		cout << "----------Server----------" << endl;
	}
	else {
		cout << "Bad Input" << endl;
		exit(EXIT_FAILURE);
	}

	InitserviceName(); //Build Strings for Msg

	SOCKET currentConnectionSocket;
	currentConnectionSocket = InitUDPConnection();
	cout << "*Connection Opened*" << endl;

	if (app_role == Server) StartServer(currentConnectionSocket);
	else if (app_role == Client) StartClient(currentConnectionSocket);
	else {
		cout << "Unexpected Error" << endl;
		exit(EXIT_FAILURE);
	}
	
	cout << "Closing Connection." << endl;
	
	_flushall();
	getchar();

	ExitAndCloseSocket(currentConnectionSocket, EXIT_SUCCESS);
}